MNIST classification


Problem 1
In this exercise, we will use a deep learning network with supervised and unsupervised learning to classify the images in the MNIST database. Create a new project called MNISTX, select Deep Learning Network, Classification and Genetic Algorithm in the new project dialog. After creating the project, copy the MNIST database files to your project folder:
  1. trainInput.idx.gz
  2. trainTarget.idx.gz

En este ejercicio, usaremos una red de aprendizaje profundo con aprendizaje con supervisión y con aprendizaje sin supervisión. Cree un nuevo proyecto llamado MNISTX, seleccione Deep Learning Network, Classification y Genetic Algorithm en el diálogo de nuevo proyecto. Después de crear el proyecto, copie los archivos de la base de datos MNIST a la carpeta del proyecto:
  1. trainInput.idx.gz
  2. trainTarget.idx.gz

Problem 2
Edit the Unsuperv.lab file to create and train an array of Restricted Boltzmann Machines, then execute the code.
Edite el archivo Unsuperv.lab para crear y entrenar un arreglo de Máquinas Restringidas de Boltzmann, entonces ejecute el código.

MNISTX\Unsuperv.lab
//_______________________________________ 1. RBM Array
RbmArray rbm;
rbm.Create(784, 2);
rbm.SetLayer(0, 1, 200); // logsig=1
rbm.SetLayer(1, 1, 100); // logsig=1
int i = 0;
for (i = 0; i < 784; i++)
{
     rbm.SetInScaler(i, 0.0, 255.0);
}
//_______________________________________ 2. Load trainSetInput
Tensor trainInput;
trainInput.LoadIdx();
trainInput.DeleteRange(1875, 59999);
Matrix input;
trainInput.ToMatrix(input);
//_______________________________________ 3. Unsupervised Learning
rbm.Train(input, 1000, true);
rbm.Save();

Problem 3
Edit the Train.lab file to train the network using supervised learning, then execute the code.
Edite el archivo Train.lab para entrenar la red usando entrenamiento con supervisión, entonces ejecute el código.

MNISTX\Train.lab
//_______________________________________ 1. Load RBM array
RbmArray rbm;
rbm.Load();
//_______________________________________ 2. Compute interior input
Tensor trainInput;
trainInput.LoadIdx();
trainInput.DeleteRange(1875, 59999);
Matrix input;
trainInput.ToMatrix(input);
Matrix interior;
rbm.Run(input, interior);
//_______________________________________ 3. Supervised Layers
int numNeurons = rbm.GetNumOutputs();
DeepNet net;
net.Create(numNeurons, 1);
net.SetLayer(0, 1, 10); // logsig=1
//net.SetLayer(1, 1, 10); // logsig=1
int i = 0;
for (i = 0; i < 10; i++)
{
     net.SetOutScaler(i, 0.0, 1.0);
}
Tensor trainTarget;
trainTarget.LoadIdx();
trainTarget.ExpandClass();
trainTarget.DeleteRange(1875, 59999);
Matrix target;
trainTarget.ToMatrix(target);
net.SetTrainSet(interior, target, true);
net.TrainSimAnneal(
     20, //Number of Temperatures
     20, //Number Iterations
     15, //Initial Temperature
     0.001, //Final Temperature
     true, //Is Cooling Schedule Linear?
     2, //Number of Cycles
     1.0e-5, //Goal (desired mse)
     false //Use Singular Value Decomposition
);
net.TrainConjGrad(400,1.0e-10);
//_______________________________________ 4. Save the trained network
net.Save();

Problem 4
Edit the Refine.lab file to incorporate the RBM elements in the array with the deep learning network and fine tune the weights, then execute the code.
Edite el archivo Refine.lab para incorporar los elementos RBM en el arreglo con la red de aprendizaje profundo y ajustar en forma fina los pesos, entonces ejecute el código.

MNISTX\Refine.lab
//_______________________________________ 1. Load RBM array
RbmArray rbm;
rbm.Load();
//_______________________________________ 2. Load Supervised Layers
DeepNet net;
net.Load();
//_______________________________________ 3. Incorporate RBM array
net.AddRbmArray(rbm);
//_______________________________________ 4. Load training sets
Tensor trainInput;
trainInput.LoadIdx();
trainInput.DeleteRange(1875, 59999);
Matrix input;
trainInput.ToMatrix(input);
//
Tensor trainTarget;
trainTarget.LoadIdx();
trainTarget.ExpandClass();
trainTarget.DeleteRange(1875, 59999);
Matrix target;
trainTarget.ToMatrix(target);
//_______________________________________ 5. Fine tunning
net.SetTrainSet(input, target, true);
net.TrainConjGrad(400,1.0e-10);
//_______________________________________ 6. Save the trained network
net.Save();


Problem 5
Edit the CheckTrain.lab file, then execute the code to check the training.
Edite el archivo CheckTrain.lab, entonces ejecute el código para verificar el entrenamiento.

MNISTX\CheckTrain.lab
//_________________________________________ 1. Load the input tensor
Tensor trainInput;
trainInput.LoadIdx();
trainInput.DeleteRange(1875, 59999);
Matrix input;
trainInput.ToMatrix(input);
//_________________________________________ 2. Load the target (a class for each digit)
Tensor trainTarget;
trainTarget.LoadIdx();
trainTarget.ExpandClass();
trainTarget.DeleteRange(1875, 59999);
Matrix target;
trainTarget.ToMatrix(target);
//_________________________________________ 3. Load the network
DeepNet net;
net.Load();
//_________________________________________ 4. Run
Matrix output;
net.Run(input, output);
//_________________________________________ 5. Compute the Confusion Matrix
Matrix trainConf = ConfusionMatrix(output, target, 0.5);
trainConf.Save();
//_________________________________________ Compute the Number of Errors
int numErrors = toint(trainConf.GetSum()) - toint(trainConf.GetDiagonalSum());

CheckTrain

Problem 6
Edit the Validation.lab file, then execute the code to validate the performance of the network.
Edite el archivo Validation.lab, entonces ejecute el código para validar el desempeño de la red neuronal.

MNISTX\Validation.lab
//_________________________________________ 1. Load the input tensor
Tensor validInput;
validInput.LoadIdx();
validInput.DeleteRange(500, 9999);
Matrix input;
validInput.ToMatrix(input);
//_________________________________________ 2. Load the target (class for each fruit)
Tensor validTarget;
validTarget.LoadIdx();
validTarget.ExpandClass();
validTarget.DeleteRange(500, 9999);
Matrix target;
validTarget.ToMatrix(target);
//_________________________________________ 3. Load the network
DeepNet net;
net.Load();
//_________________________________________ 4. Run
Matrix output;
net.Run(input, output);
//_________________________________________ 5. Compute the Confusion Matrix
Matrix validConf = ConfusionMatrix(output, target, 0.5);
validConf.Save();
//_________________________________________ Compute the Number of Errors
int numErrors = toint(validConf.GetSum()) - toint(validConf.GetDiagonalSum());

Validation

ValNumErrors

© Copyright 2000-2021 Wintempla selo. All Rights Reserved. Jul 22 2021. Home